package com.example.demo.util;

import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: yby
 * @create: 2020-05-20 08:59
 **/
public class DateUtil {

    // 校验日期时间是否在当前时间到未来180天之间
    public static boolean isValidRange(String expireTime, String formatPattern) {
        try {
            // 解析输入日期时间
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern);
            LocalDateTime inputDateTime = LocalDateTime.parse(expireTime, formatter);

            // 获取当前时间和180天后的时间
            LocalDateTime now = LocalDateTime.now();
            LocalDateTime maxDateTime = now.plusDays(180);

            // 判断是否在范围内（>= now && <= now+180天）
            return !inputDateTime.isBefore(now) && !inputDateTime.isAfter(maxDateTime);
        } catch (DateTimeParseException e) {
            // 日期格式错误
            return false;
        }
    }



    public static void main(String[] args) {

        System.out.println(isValidRange("2024-12-17 00:00:00", "yyyy-MM-dd HH:mm:ss"));

//        Byte b = 8;
//        System.out.println(b.equals(8));
//        System.out.println(b == 8);



    }

}
